<template>
  <el-dialog
    title="题目预览"
    :visible="dialogVisible"
    width="50%"
    @close="closeDialog"
    class="box"
    v-loading='loading'
    @open='openDialog'
  >
    <!-- 预览 -->
    <el-descriptions :column="4" >
      <el-descriptions-item label="【题型】">{{questionList.questionType|formatterType}}</el-descriptions-item>
      <el-descriptions-item label="【编号】">{{questionList.id}}</el-descriptions-item>
      <el-descriptions-item label="【难度】">{{questionList.difficulty|formatterDif}}</el-descriptions-item>
      <el-descriptions-item label="【标签】">{{questionList.tags}}</el-descriptions-item>
      <el-descriptions-item label="【学科】">{{questionList.subjectName}}</el-descriptions-item>
      <el-descriptions-item label="【目录】">{{questionList.directoryName}}</el-descriptions-item>
      <el-descriptions-item label="【方向】">{{questionList.direction}}</el-descriptions-item>
    </el-descriptions>
    <el-divider class="divider"></el-divider>
    <p style="margin:5px 0" class="question-titel">【题干】：</p>
   <div class="question-content">
     <!-- 题目 -->
  <div  style="color:blue" v-html="questionList.question"></div>
    <div v-if="questionList.questionType !== '3'" class="choice-question">
      <span >{{questionList.questionType|formatterType}}</span>
      <span > 选项：(以下选中的选项为正确答案)</span>
      <!-- 选项 -->
    <div class="options" v-for="item in questionList.options" :key="item.id">
      <el-radio v-if="questionList.questionType === '1'" :value="item.isRight" :label="1" style="display: block" >{{item.title}}</el-radio>
      <el-checkbox v-if="questionList.questionType === '2'" :value="item.isRight?true:false">{{item.title}}</el-checkbox>
    </div>
    </div>
   </div>
    <el-divider class="divider"></el-divider>
    【参考答案】：<el-button  type="danger" size="mini" @click="showVideo">视频答案预览</el-button>
        <div class="videoBox"  v-show="show" >
          <video ref="video" :src="questionList.videoURL" controls></video>
        </div>
  <el-divider class="divider"></el-divider>
     <div class="answer">
        【答案解析】：
       <div style="display:inline-block" v-html="questionList.answer"></div>
    </div>
    <el-divider class="divider"></el-divider>
    <p class="question-titel">【题目备注】：{{questionList.directoryName}}</p>
     <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="closeDialog">关闭</el-button>
  </span>
  </el-dialog>
</template>

<script>
import { detail } from '@/api/hmmm/questions.js'
import { difficulty, questionType } from '@/api/hmmm/constants.js'
export default {
  name: 'Preview',
  props: {
    questionID: {
      type: Number,
      default: 0
    }
  },
  data () {
    return {
      loading: false,
      dialogVisible: false,
      questionList: {},
      show: false
    }
  },
  filters: {
    formatterDif (val) {
      if (val) return difficulty.find(item => item.value === +val).label
    },
    formatterType (val) {
      if (val) return questionType.find(item => item.value === +val).label + '题'
    }
  },
  created () {},
  methods: {
    // 关闭对话框
    closeDialog () {
      this.dialogVisible = false
      // 关闭video
      this.$refs.video.pause()
      this.show = false
    },
    // 获取题目信息
    async openDialog () {
      this.dialogVisible = true
      this.loading = true
      const res = await detail({ id: this.questionID })
      console.log(res)
      this.questionList = res.data
      this.loading = false
    },
    showVideo () {
      this.show = true
      this.$refs.video.play()
    }

  }
}
</script>

<style scoped lang='scss'>
.box {
  ::v-deep {
    .divider {
      margin: 0;
    }
    // .question-titel{
    //   height:15px
    // }
    .question-content{
      .options{
        padding: 8px 0;
    }
  }
  }
}
</style>
